package com.isolate.run;

import com.zaxxer.nuprocess.NuAbstractProcessHandler;
import com.zaxxer.nuprocess.NuProcess;
import lombok.extern.slf4j.Slf4j;

import java.nio.ByteBuffer;

/**
 * @author gaozhongbao
 * @date 2020/08/14
 **/
@Slf4j
public class TestHandler extends NuAbstractProcessHandler {

    private NuProcess nuProcess;

    private StringBuilder stringBuilder;

    @Override
    public void onStart(NuProcess nuProcess) {
        this.nuProcess = nuProcess;
        this.stringBuilder = new StringBuilder();
    }

    public TestHandler() {
        super();
    }

    public void setStringBuilder(StringBuilder stringBuilder) {
        this.stringBuilder = stringBuilder;
    }

    @Override
    public void onPreStart(NuProcess nuProcess) {
        super.onPreStart(nuProcess);
    }

    @Override
    public void onExit(int statusCode) {
        super.onExit(statusCode);
    }

    @Override
    public void onStderr(ByteBuffer buffer, boolean closed) {
        super.onStderr(buffer, closed);
    }

    @Override
    public void onStdout(ByteBuffer buffer, boolean closed) {
        byte[] bytes = new byte[buffer.remaining()];
        buffer.get(bytes);
        log.info("res:[{}]", new String(bytes));
    }
}
